package fr.vahren.processing.entity;

import java.util.ArrayList;
import java.util.List;

import processing.core.PApplet;
import traer.physics.Particle;
import fr.vahren.processing.Main;

public class Atom extends Entity {

	private List<Electron> electrons;

	public Atom(Particle particle, PApplet pA, boolean isAnti) {
		electrons = new ArrayList<Electron>();
		this.particle = particle;
		this.pA = pA;
		anti = isAnti;

		particle.makeFixed();
	}

	public void draw() {
		pA.pushMatrix();
		pA.noStroke();
		if (anti) {
			if (picked) {
				pA.fill(0, 155, 205);
			} else {
				pA.fill(0, 205, 255);
			}
		} else {
			if (picked) {
				pA.fill(255, 100, 50);
			} else {
				pA.fill(255, 50, 0);
			}
		}
		pA.translate(particle.position().x(), particle.position().y(), particle
				.position().z());
		pA.sphere(Main.ATOM_SIZE);
		pA.popMatrix();
	}

	@Override
	public void checkVelocity() {
	}

	public void addElectron(Electron e) {
		if (!electrons.contains(e)) {
			electrons.add(e);
		}
	}

	/**
	 * @return the electrons
	 */
	public List<Electron> getElectrons() {
		return electrons;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "Atom [particle=" + particle + "]";
	}

	public boolean containsOppositeElectrons(boolean anti) {
		for (Electron e : electrons) {
			if (e.isAnti() != anti) {
				return true;
			}
		}
		return false;

	}

}
